package cnm.dao.hibernate;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import cnm.dao.ColumnDAO;
import cnm.model.Column;

public class ColumnHibernateDAO extends GenericHibernateDAO<Column> implements ColumnDAO
{
	public ColumnHibernateDAO()
	{
		super(Column.class);
	}

	public Column findByUuid(final String uuid)
	{
		return (Column) getHibernateTemplate().execute(new HibernateCallback()
		{
			public Object doInHibernate(Session session) throws HibernateException
			{
				Query query = session.createQuery("from Column c where c.columnUuid = :uuid")
					.setString("uuid", uuid);
				return query.uniqueResult();
			}
		}, true);
	}
	
	public Long getCount()
	{
		return (Long) getHibernateTemplate().execute(new HibernateCallback()
		{
			public Object doInHibernate(Session session) throws HibernateException
			{
				Query query = session.createQuery("select count(*) from Column c");							
				return query.uniqueResult();
			}
		}, true);
	}
	
	
}
